/**
 * Created by hychangkong on 2018-10-18.
 */
$(function () {

    $("#jqGrid").jqGrid({
        url: baseURL + 'jysjxs/list',
        datatype: "json",
        colModel: [
            { label: '序号', name: '', index: "", width: 10 },
            { label: 'id', name: 'id', index: "id", width: 45, key: true,hidden:true },
            { label: '学号', name: 'xsId', index: 'xsId', width: 80 },
            { label: '姓名', name: 'candidate', index: 'candidate', width: 80 },
            { label: '答题用时（分钟）', name: 'sc', index: 'sc', width: 80 },
            { label: '总分', name: 'sjScore', index: 'sjScore', width: 80 },
            { label: '操作', name: 'name', index: 'name', width: 80,formatter: function(value, options, row){
                if ( row.sjScore == null  )
                    return '<button onclick="openWin(\''+row.id+'\')" class="btn btn1">评卷</button>';
                else
                    return '<button onclick="openWinDetail(\''+row.id+'\')" class="btn btn1">查看</button>';
            } },
        ],
        viewrecords: true,
        height: 365,
        rowNum: 30,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: false,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });

    vm.getKcxx();
    vm.getSjList();


});

function openWin(ids){
    // alert(ids);
   window.location.href = '/modules/test/marking.html?xsId='+ids;
}

function openWinDetail(ids){
    // alert(ids);
   window.location.href = '/modules/test/markingDetail.html?xsId='+ids;
}


var vm = new Vue({
    el:'#rrapp',
    data:{
        jyKcxxList:[

        ],
        sjlist:[],
        endTime:"",
        startTime:"",
        kcId:""
    },
    updated:function(){

    },
    methods: {
        itemClick:function(item){
           // alert(item.id);
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                page:page,
                postData:{'sjId':item.id,state:1}
            }).trigger("reloadGrid");
        },
        getSjList:function(){
            //取得课程信息
            var url = "jysjinfo/findList";
            var b = $("#ECalendar_date_begin").val() == ""?'':$("#ECalendar_date_begin").val()+":00";
            var e = $("#ECalendar_date_end").val() == ""?'':$("#ECalendar_date_end").val()+":00";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                // contentType: "application/json",
                 data: {
                     kcId:vm.kcId,
                     endTime:e,
                    startTime:b,
                     deleteState:0
                 },
                success: function (r) {
                    if (r.code == 0) {
                        vm.sjlist = r.page;
                        var page = $("#jqGrid").jqGrid('getGridParam','page');
                        $("#jqGrid").jqGrid('setGridParam',{
                            page:page,
                            postData:{'sjId':0,state:1}
                        }).trigger("reloadGrid");
                    }
                }
            });

        },
        getKcxx: function () {
            //取得课程信息
            var url = "jykcxx/list";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/json",
                // data: JSON.stringify(vm.jySjTitle),
                success: function (r) {
                    if (r.code == 0) {
                        vm.jyKcxxList = r.page.list;
                    }
                }
            });
        }
    }
});